from uniutils import pretrain_model_download, load_raw_eeg
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns



file_name = '/data2/npc/lixiang/playground/aaa/ZuCo2/task2 - TSR/Raw data/YAG/YAG_TSR1_EEG.mat'
rawdata = load_raw_eeg(file_name)
data = list(rawdata.reshape((1, -1)).squeeze())
Channels = [_ for _ in range(rawdata.shape[0])]*rawdata.shape[1]
# 将数据转换为pandas DataFrame
dic = {'data':data, 'Channels':Channels}
df = pd.DataFrame(dic)

# 绘制箱形图
plt.figure(figsize=(128, 8))  # 可以根据需要调整大小
sns.boxplot(x='Channels', y='data', data=df)

# 设置标题和标签
plt.title('YAG_TSR1_EEG')
plt.xlabel('Channels')
plt.ylabel('Values')
plt.tight_layout()
# 显示图形
plt.savefig('./plots/boxplot.png')
plt.close()  # 关闭图形，防止重叠



channels = np.array([i for i in range(rawdata.shape[0])])
for i in range(0, rawdata.shape[0], 8):
    x = [_ for _ in range(rawdata.shape[1])]*8
    y_ = rawdata[i:i+8, :]
    y = []
    for j in range(8):
        y += list(y_[j, :])
    g_channel = list(channels[i:i+8])*rawdata.shape[1]
    dic = {'TimeStep':x, 'Values':y, 'Channel':g_channel}
    df = pd.DataFrame(dic)
    plt.figure(figsize=(64, 8))  # 可以根据需要调整大小
    sns.lineplot(x="TimeStep", y="Values",hue="Channel", data=df)
    # 显示图形
    plt.tight_layout()
    plt.savefig(f'./plots/lineplot_{i}.png')
    plt.close()  # 关闭图形，防止重叠
